/*
* Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
*/
package com.hyyt.shopjsp.syncData.controller;

import com.hyyt.shopjsp.common.controller.BaseController;
import com.hyyt.shopjsp.redis.service.IRedisInitializingBasicDataService;
import com.hyyt.shopjsp.util.common.ResultMsg;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 同步数据controller
 *
 * @author: ankang
 * @Date 2016/7/26 0026 上午 10:02
 */
@Controller
@RequestMapping("/back/synchronize/data/")
public class SynchronizeDataController extends BaseController {

    /**
     * 加载日志
     */
    Logger logger = Logger.getLogger(SynchronizeDataController.class);

    /**
     * 初始化Redis接口
     */
    @Resource
    private IRedisInitializingBasicDataService redisInitializingBasicDataService;

    /**
     * 手动同步数据字典数据
     *
     * @return
     */
    @RequestMapping("syncKeyBookInfo")
    @ResponseBody
    public ResultMsg syncKeyBookInfo() {
        ResultMsg resultMsg = new ResultMsg(false);
        boolean result = redisInitializingBasicDataService.initKeyBookDataInfo();//同步数据字典
        if (result) {
            resultMsg.setSuccess(true);
            resultMsg.setMsg("同步数据字典数据成功!");
        }
        return resultMsg;
    }

    /**
     * 手动同步系统基础配置
     *
     * @return
     */
    @RequestMapping("syncSystemConfig")
    @ResponseBody
    public ResultMsg syncSystemConfig() {
        ResultMsg resultMsg = new ResultMsg(false);
        boolean result = redisInitializingBasicDataService.initSystemConfig();//同步系统基础配置
        if (result) {
            resultMsg.setSuccess(true);
            resultMsg.setMsg("系统基础配置数据同步成功!");
        }
        return resultMsg;
    }

    /**
     * 手动同步自定义业务状态数据
     *
     * @return
     */
    @RequestMapping("syncKeyBookStatusRelate")
    @ResponseBody
    public ResultMsg syncKeyBookStatusRelate() {
        ResultMsg resultMsg = new ResultMsg(false);
        boolean result = redisInitializingBasicDataService.initKeyBookStatusRelate();//同步自定义业务状态数据
        if (result) {
            resultMsg.setSuccess(true);
            resultMsg.setMsg("自定义业务状态数据同步成功!");
        }
        return resultMsg;
    }

    /**
     * 手动同步首页数据字典数据
     *
     * @return
     */
    @RequestMapping("syncHomeKeyBook")
    @ResponseBody
    public ResultMsg syncHomeKeyBook() {
        ResultMsg resultMsg = new ResultMsg(false);
        boolean result = redisInitializingBasicDataService.initHomeKeyBookDataInfo();
        if (result) {
            resultMsg.setSuccess(true);
            resultMsg.setMsg("首页数据字典数据同步成功!");
        }
        return resultMsg;
    }

    /**
     * 手动同步手机首页数据字典
     *
     * @return
     */
    @RequestMapping("syncPhoneHomeKeyBook")
    @ResponseBody
    public ResultMsg syncPhoneHomeKeyBook() {
        ResultMsg resultMsg = new ResultMsg(false);
        boolean result = redisInitializingBasicDataService.initPhoneKeyBookDataInfo();
        if (result) {
            resultMsg.setSuccess(true);
            resultMsg.setMsg("商品分类数据同步成功!");
        }
        return resultMsg;
    }

}